package com.sundhage.gui {
	import flash.display.*;
	
	public class JSBusy extends Sprite {
		private var _root:*;
		private var gfx:Sprite = new Sprite();
		private var oldTarget:DisplayObjectContainer;
		private var onTop:*;
		private var putBack:Boolean;
		public function show(onTop:* = null,  putBack:Boolean = false):void {
			this.putBack = putBack;
			if (putBack) {
				this.onTop = onTop;
				oldTarget = onTop.parent;
			}	
			if (onTop == null) onTop = new Sprite();
			_root.addChild(gfx);
			_root.addChild(onTop);
			
		}
		
		public function hide():void {
			try {
				_root.removeChild(gfx);
			} catch (e:Error) {}
			
			if (putBack) {
				try {
					oldTarget.addChild(onTop);
					trace("hum: "+oldTarget);
				} catch (e:Error) {}
			}
		}
		
		public function JSBusy(root:*, color:uint=0x0, alpha:Number = 0.2) {
			this._root = root;
			
			gfx.graphics.beginFill(color, alpha);
			gfx.graphics.drawRect(0,0,root.stage.stageWidth, root.stage.stageHeight);
			gfx.graphics.endFill();
		}

	}
}